package com.wxl.common.util

import java.text.DateFormat
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*

/**
 * create file time : 2021/3/8
 * create user : wxl
 * subscribe :
 */
class DateUtils {
    companion object {
        val HMS = SimpleDateFormat("HH:mm:ss")
        val YMD = SimpleDateFormat("yyyy:MM:dd")
        val YMDHMS = SimpleDateFormat("yyyy:MM:dd HH:mm:ss")

        fun getHMS(): String {
            return HMS.format(Date())
        }

        fun getYMD(): String {
            return YMD.format(Date())
        }

        fun getYMDHMS():String{
            return YMDHMS.format(Date())
        }

        fun getYMDWeek() : String{
            val calendar = Calendar.getInstance()
            calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00"))
            val mYear = calendar.get(Calendar.YEAR) // 获取当前年份
            val mMonth = calendar.get(Calendar.MONTH) + 1// 获取当前月份
            val mDay = calendar.get(Calendar.DAY_OF_MONTH)// 获取当前月份的日期号码
            var mWay : String = calendar.get(Calendar.DAY_OF_WEEK).toString()
            when {
                "1".equals(mWay) -> {
                    mWay ="天"
                }
                "2".equals(mWay) -> {
                    mWay ="一"
                }
                "3".equals(mWay) -> {
                    mWay ="二"
                }
                "4".equals(mWay) -> {
                    mWay ="三"
                }
                "5".equals(mWay) -> {
                    mWay ="四"
                }
                "6".equals(mWay) -> {
                    mWay ="五"
                }
                "7".equals(mWay) -> {
                    mWay ="六"
                }
            }
            return "$mYear 年 $mMonth 月 $mDay 日  星期 $mWay"
        }

        /**
         * 获取当前时间 格式是 2012年12月12日
         *
         * @return
         */
        fun getCurrentDate(): String? {
            val time = System.currentTimeMillis()
            val date = Date(time)
            val format: DateFormat = SimpleDateFormat("yyyy年MM月dd日")
            return format.format(date)
        }


        fun getNowTime(): String? {
            return SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())
        }

        fun getYMDHMSTime(time:Long) : String{
            return SimpleDateFormat("HH:mm:ss").format(Date(time))
        }

        /**
         *
         * @return
         */
        fun getCurrentTime(): Long {
            return System.currentTimeMillis() / 1000
        }


        fun getTime(time: String?): Long {
            val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
            var returnTime = 0L
            try {
                returnTime = sdf.parse(time).time
            } catch (e: ParseException) {
                e.printStackTrace()
            }
            return returnTime
        }

    }



}